import { Controller, Get, Post } from "@nestjs/common";
import { UserService } from "./service/user.service";
import { ApiRes, RequsetUser } from "src/decorator";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import { UserInfo } from "src/common/model";

@ApiTags("User - 模块")
@Controller("user")
export class UserController {
    constructor(private readonly userService: UserService) {}

    @ApiOperation({ summary: "获取用户信息" })
    @ApiRes({ type: UserInfo })
    @Post("info")
    @Get("info")
    async info(@RequsetUser() requsetUser: RequsetUser): Promise<UserInfo> {
        const user = await this.userService.find(requsetUser.id);
        return {
            ...requsetUser,
            roles: user.roles,
        };
    }
}
